﻿#ifndef OPT_H
#define OPT_H

#include "pagetype.h"
#include "risc.h"
#include "x86.h"

class TLB_OPT_x86 :public TLB
{
private:
	uint64_t cr3;
	uint64_t RvBA, cr5, cr6, cr7;
	PTE_x86<8> l1i_4k[8], l1i_2m[4], l1i_1g[2];
	PTE_x86<8> l1d_4k[16], l1d_2m[4], l1d_1g[2];
	PTE_x86<8> l2_4k[256], l2_2m[128], l2_1g[64];
	bool opt_on;
	void l1i_search();
	void l1d_search();
	void l2_search();
	void swap();

public:
	TLB_OPT_x86() = default;
	~TLB_OPT_x86() = default;
	void init(uint64_t cr3, uint64_t RvBA)
	{
		this->cr3 = cr3;
		this->RvBA = RvBA;
	}
	void tick();
	void reset();
};
class TLB_OPT_RISC :public TLB
{
private:
	uint64_t satp;
	uint64_t RvBA;
	PTE_RISC l1i_4k[8], l1i_2m[4], l1i_1g[2];
	PTE_RISC l1d_4k[16], l1d_2m[4], l1d_1g[2];
	PTE_RISC l2_4k[256], l2_2m[128], l2_1g[64];
	void l1i_search();
	void l1d_search();
	void l2_search();
	void swap();

public:
	TLB_OPT_RISC() = default;
	~TLB_OPT_RISC() = default;
	void init(uint64_t satp, uint64_t RvBA)
	{
		this->satp = satp;
		this->RvBA = RvBA;
	}
	void tick();
	void reset();
};

#endif